<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
     
      <el-form-item label="会员姓名" prop="membersName">
        <el-input
          v-model="queryParams.membersName"
          placeholder="请输入会员姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="会员工号" prop="membersNum">
        <el-input
          v-model="queryParams.membersNum"
          placeholder="请输入会员工号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:members:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:members:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:members:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:members:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="membersList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="会员主键id" align="center" prop="membersId" />
      <el-table-column label="用户id" align="center" prop="userId" />
      <el-table-column label="会员姓名" align="center" prop="membersName" />
      <el-table-column label="会员工号" align="center" prop="membersNum" />
      <el-table-column label="会员性别 0男 1女 2未知" align="center" prop="membersSex" />
      <el-table-column label="会员出生日期" align="center" prop="membersBir" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.membersBir, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="会员学历" align="center" prop="membersBackground" />
      <el-table-column label="会员民族" align="center" prop="membersNation" />
      <el-table-column label="会员政治面貌" align="center" prop="membersPolitical" />
      <el-table-column label="会员来校时间" align="center" prop="membersSchoolDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.membersSchoolDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="会员联系电话" align="center" prop="membersTel" />
      <el-table-column label="会员所在单位id" align="center" prop="deptId" />
      <el-table-column label="会员所在协会id" align="center" prop="societyId" />
      <el-table-column label="婚姻状况 0未婚 1已婚 2离异(无小孩) 3离异(带小孩) 4离异(不带小孩) 5丧偶(无小孩) 6丧偶(有小孩)" align="center" prop="membersMaritalStatus" />
      <el-table-column label="配偶是否为校内职工 0否 1是" align="center" prop="membersSpouseCampusStaff" />
      <el-table-column label="籍贯" align="center" prop="membersNativePlace" />
      <el-table-column label="家庭住址" align="center" prop="membersAddress" />
      <el-table-column label="所在校区" align="center" prop="school" />
      <el-table-column label="用人方式 0在编人员 1校聘人员  2自聘人员  3其他人员  4博士后" align="center" prop="membersModeEmployment" />
      <el-table-column label="个人工作简历" align="center" prop="membersResume" />
      <el-table-column label="家庭主要成员/单位" align="center" prop="membersMainFamily" />
      <el-table-column label="特长/爱好" align="center" prop="membersHobby" />
      <el-table-column label="会员备注" align="center" prop="membersRemarks" />
      <el-table-column label="个人照片" align="center" prop="membersImg" />
      <el-table-column label="手签" align="center" prop="membersSign" />
      <el-table-column label="身份证号码" align="center" prop="membersContactNumber" />
      <el-table-column label="人员状态 0在职 1 离职  2退休" align="center" prop="membersAdmissionTime" />
      <el-table-column label="会员状态 0正常 1退会 2转会" align="center" prop="membersStatus" />
      <el-table-column label="年龄" align="center" prop="membersAge" />
      <el-table-column label="是否是会员 0是 1不是" align="center" prop="membersIsStatus" />
      <el-table-column label="国籍 0中国 1外国" align="center" prop="membersNationality" />
      <el-table-column label="身份类别 0身份证  1护照 2士官证 3港澳通行证 4台湾居民来往大陆通行证" align="center" prop="membersIdentityType" />
      <el-table-column label="身份类型对应的身份号码" align="center" prop="membersIdentityNum" />
      <el-table-column label="技术等级 0初级 1中级 2高级" align="center" prop="membersTechnical" />
      <el-table-column label="专业技术职称 0正高级 1副高级 2中级 3初级 4其他" align="center" prop="membersProfessional" />
      <el-table-column label="邮箱" align="center" prop="membersEmail" />
      <el-table-column label="行政职务" align="center" prop="membersAdministrative" />
      <el-table-column label="配偶姓名" align="center" prop="membersSpouseName" />
      <el-table-column label="户籍类型 0城镇户口  1农业户口" align="center" prop="membersHouseholdType" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:members:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:members:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改会员对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="用户id" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户id" />
        </el-form-item>
        <el-form-item label="会员姓名" prop="membersName">
          <el-input v-model="form.membersName" placeholder="请输入会员姓名" />
        </el-form-item>
        <el-form-item label="会员工号" prop="membersNum">
          <el-input v-model="form.membersNum" placeholder="请输入会员工号" />
        </el-form-item>
        <el-form-item label="会员出生日期" prop="membersBir">
          <el-date-picker clearable
            v-model="form.membersBir"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择会员出生日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="会员学历" prop="membersBackground">
          <el-input v-model="form.membersBackground" placeholder="请输入会员学历" />
        </el-form-item>
        <el-form-item label="会员民族" prop="membersNation">
          <el-input v-model="form.membersNation" placeholder="请输入会员民族" />
        </el-form-item>
        <el-form-item label="会员政治面貌" prop="membersPolitical">
          <el-input v-model="form.membersPolitical" placeholder="请输入会员政治面貌" />
        </el-form-item>
        <el-form-item label="会员来校时间" prop="membersSchoolDate">
          <el-date-picker clearable
            v-model="form.membersSchoolDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择会员来校时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="会员联系电话" prop="membersTel">
          <el-input v-model="form.membersTel" placeholder="请输入会员联系电话" />
        </el-form-item>
        <el-form-item label="会员所在单位id" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入会员所在单位id" />
        </el-form-item>
        <el-form-item label="会员所在协会id" prop="societyId">
          <el-input v-model="form.societyId" placeholder="请输入会员所在协会id" />
        </el-form-item>
        <el-form-item label="配偶是否为校内职工 0否 1是" prop="membersSpouseCampusStaff">
          <el-input v-model="form.membersSpouseCampusStaff" placeholder="请输入配偶是否为校内职工 0否 1是" />
        </el-form-item>
        <el-form-item label="籍贯" prop="membersNativePlace">
          <el-input v-model="form.membersNativePlace" placeholder="请输入籍贯" />
        </el-form-item>
        <el-form-item label="家庭住址" prop="membersAddress">
          <el-input v-model="form.membersAddress" placeholder="请输入家庭住址" />
        </el-form-item>
        <el-form-item label="所在校区" prop="school">
          <el-input v-model="form.school" placeholder="请输入所在校区" />
        </el-form-item>
        <el-form-item label="用人方式 0在编人员 1校聘人员  2自聘人员  3其他人员  4博士后" prop="membersModeEmployment">
          <el-input v-model="form.membersModeEmployment" placeholder="请输入用人方式 0在编人员 1校聘人员  2自聘人员  3其他人员  4博士后" />
        </el-form-item>
        <el-form-item label="个人工作简历" prop="membersResume">
          <el-input v-model="form.membersResume" placeholder="请输入个人工作简历" />
        </el-form-item>
        <el-form-item label="家庭主要成员/单位" prop="membersMainFamily">
          <el-input v-model="form.membersMainFamily" placeholder="请输入家庭主要成员/单位" />
        </el-form-item>
        <el-form-item label="特长/爱好" prop="membersHobby">
          <el-input v-model="form.membersHobby" placeholder="请输入特长/爱好" />
        </el-form-item>
        <el-form-item label="会员备注" prop="membersRemarks">
          <el-input v-model="form.membersRemarks" placeholder="请输入会员备注" />
        </el-form-item>
        <el-form-item label="个人照片" prop="membersImg">
          <el-input v-model="form.membersImg" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="手签" prop="membersSign">
          <el-input v-model="form.membersSign" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="身份证号码" prop="membersContactNumber">
          <el-input v-model="form.membersContactNumber" placeholder="请输入身份证号码" />
        </el-form-item>
        <el-form-item label="人员状态 0在职 1 离职  2退休" prop="membersAdmissionTime">
          <el-input v-model="form.membersAdmissionTime" placeholder="请输入人员状态 0在职 1 离职  2退休" />
        </el-form-item>
        <el-form-item label="年龄" prop="membersAge">
          <el-input v-model="form.membersAge" placeholder="请输入年龄" />
        </el-form-item>
        <el-form-item label="国籍 0中国 1外国" prop="membersNationality">
          <el-input v-model="form.membersNationality" placeholder="请输入国籍 0中国 1外国" />
        </el-form-item>
        <el-form-item label="身份类型对应的身份号码" prop="membersIdentityNum">
          <el-input v-model="form.membersIdentityNum" placeholder="请输入身份类型对应的身份号码" />
        </el-form-item>
        <el-form-item label="技术等级 0初级 1中级 2高级" prop="membersTechnical">
          <el-input v-model="form.membersTechnical" placeholder="请输入技术等级 0初级 1中级 2高级" />
        </el-form-item>
        <el-form-item label="专业技术职称 0正高级 1副高级 2中级 3初级 4其他" prop="membersProfessional">
          <el-input v-model="form.membersProfessional" placeholder="请输入专业技术职称 0正高级 1副高级 2中级 3初级 4其他" />
        </el-form-item>
        <el-form-item label="邮箱" prop="membersEmail">
          <el-input v-model="form.membersEmail" placeholder="请输入邮箱" />
        </el-form-item>
        <el-form-item label="行政职务" prop="membersAdministrative">
          <el-input v-model="form.membersAdministrative" placeholder="请输入行政职务" />
        </el-form-item>
        <el-form-item label="配偶姓名" prop="membersSpouseName">
          <el-input v-model="form.membersSpouseName" placeholder="请输入配偶姓名" />
        </el-form-item>
        <el-form-item label="删除标识 0未删除 2已删除" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标识 0未删除 2已删除" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listMembers, getMembers, delMembers, addMembers, updateMembers } from "@/api/members/members";

export default {
  name: "Members",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 会员表格数据
      membersList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        membersName: null,
        membersNum: null,
        membersSex: null,
        membersBir: null,
        membersBackground: null,
        membersNation: null,
        membersPolitical: null,
        membersSchoolDate: null,
        membersTel: null,
        deptId: null,
        societyId: null,
        membersMaritalStatus: null,
        membersSpouseCampusStaff: null,
        membersNativePlace: null,
        membersAddress: null,
        school: null,
        membersModeEmployment: null,
        membersResume: null,
        membersMainFamily: null,
        membersHobby: null,
        membersRemarks: null,
        membersImg: null,
        membersSign: null,
        membersContactNumber: null,
        membersAdmissionTime: null,
        membersStatus: null,
        membersAge: null,
        membersIsStatus: null,
        membersNationality: null,
        membersIdentityType: null,
        membersIdentityNum: null,
        membersTechnical: null,
        membersProfessional: null,
        membersEmail: null,
        membersAdministrative: null,
        membersSpouseName: null,
        membersHouseholdType: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询会员列表 */
    getList() {
      this.loading = true;
      listMembers(this.queryParams).then(response => {
        this.membersList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        membersId: null,
        userId: null,
        membersName: null,
        membersNum: null,
        membersSex: null,
        membersBir: null,
        membersBackground: null,
        membersNation: null,
        membersPolitical: null,
        membersSchoolDate: null,
        membersTel: null,
        deptId: null,
        societyId: null,
        membersMaritalStatus: null,
        membersSpouseCampusStaff: null,
        membersNativePlace: null,
        membersAddress: null,
        school: null,
        membersModeEmployment: null,
        membersResume: null,
        membersMainFamily: null,
        membersHobby: null,
        membersRemarks: null,
        membersImg: null,
        membersSign: null,
        membersContactNumber: null,
        membersAdmissionTime: null,
        membersStatus: null,
        membersAge: null,
        membersIsStatus: null,
        membersNationality: null,
        membersIdentityType: null,
        membersIdentityNum: null,
        membersTechnical: null,
        createTime: null,
        membersProfessional: null,
        membersEmail: null,
        membersAdministrative: null,
        membersSpouseName: null,
        membersHouseholdType: null,
        createBy: null,
        updateBy: null,
        updateTime: null,
        delFlag: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.membersId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加会员";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const membersId = row.membersId || this.ids
      getMembers(membersId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改会员";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.membersId != null) {
            updateMembers(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addMembers(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const membersIds = row.membersId || this.ids;
      this.$modal.confirm('是否确认删除会员编号为"' + membersIds + '"的数据项？').then(function() {
        return delMembers(membersIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/members/export', {
        ...this.queryParams
      }, `members_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
